using System;
using System.Collections.Generic;
using System.Text;

namespace PocketAbapa
{
	public class PlayersList : List<Player>
	{
		public PlayersList(int NumberOfPlayers) : base(NumberOfPlayers)
		{
			for (int i = 0; i < NumberOfPlayers; i++)
			{
				this.Add(new Player());
			}
		}

		#region Events

		public event EventHandler CurrentPlayerChanged;

		protected void RaiseCurrentPlayerChanged()
		{
			if (CurrentPlayerChanged != null)
			{
				CurrentPlayerChanged(this, null);
			}
		}

		#endregion

		public void Reset()
		{
			CurrentPlayerIndex = 0;
			foreach (Player p in this)
			{
				p.Score = 0;
			}
		}

		#region Current

		public Player Current
		{
			get
			{
				return this[CurrentPlayerIndex];
			}
		}

		private int mCurrentPlayerIndex = 0;
		public int CurrentPlayerIndex
		{
			get
			{
				return mCurrentPlayerIndex;
			}
			set
			{
				mCurrentPlayerIndex = value;
				RaiseCurrentPlayerChanged();
			}
		}

		public void SetNextPlayer()
		{
			CurrentPlayerIndex++;
			if (CurrentPlayerIndex >= this.Count)
			{
				CurrentPlayerIndex = 0;
			}
		}

		#endregion
	}
}
